<script setup lang="ts">
  import { defineComponent, ref, reactive } from 'vue'
  import { VxeGridProps } from 'vxe-table'

  interface UserVO {
    id: number;
    name: string;
    role: string;
    sex: string;
    age: number;
    address: string;
  }

  const tableData = ref<UserVO[]>([
    { id: 10001, name: 'Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
    { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
    { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
    { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
  ])

  const gridOptions = reactive<VxeGridProps<UserVO>>({
    border: true,
    columns: [
      { type: 'seq', width: 50 },
      { field: 'name', title: 'Name', slots: { default: 'name' } },
      { field: 'sex', title: 'Sex', showHeaderOverflow: true },
      { field: 'address', title: 'Address', showOverflow: true }
    ],
    data: [
      { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
      { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
      { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
      { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
    ]
  })

  let num = 999
  let config1 = ref({
    number: [num],
    content: '{nt}个'
  })
  function changeNum() {
    num === 999 ? num = 1: num = 999
    config1.value.number = [num]
  }
  const config2 = ref({
    data: [
      ['行1列1', '行1列2', '行1列3'],
      ['行2列1', '行2列2', '行2列3'],
      ['行3列1', '行3列2', '行3列3'],
      ['行4列1', '行4列2', '行4列3'],
      ['行5列1', '行5列2', '行5列3'],
      ['行6列1', '行6列2', '行6列3'],
      ['行7列1', '行7列2', '行7列3'],
      ['行8列1', '行8列2', '行8列3'],
      ['行9列1', '行9列2', '行9列3'],
      ['行10列1', '行10列2', '行10列3']
    ],
    rowNum: 3
  })

</script>

<template>
  <div>
    <vxe-table border :data="tableData">
      <vxe-column type="seq" width="60"></vxe-column>
      <vxe-column field="name" title="Name">
        <template #default="{ row }">
          <span>自定义插槽模板 {{ row.name }}</span>
        </template>
      </vxe-column>
      <vxe-column field="sex" title="Sex"></vxe-column>
      <vxe-column field="age" title="Age"></vxe-column>
    </vxe-table>

    <vxe-grid v-bind="gridOptions">
      <template #name="{ row }">
        <span>自定义插槽模板 {{ row.name }}</span>
      </template>
    </vxe-grid>

    <dv-decoration-3 style="width:250px;height:30px;" />
    <dv-loading>Loading...</dv-loading>
    <dv-decoration-12 style="width:150px;height:150px;" />
    <dv-digital-flop :config="config1" style="width:100px;height:50px;" />
    <el-button @click="changeNum">变化数字</el-button>
    <dv-scroll-board :config="config2" style="width:500px;height:220px" />
  </div>
</template>

<style scoped></style>
